<style lang="less" scoped>
/deep/.el-dialog--center .el-dialog__body {
  padding: 7px 0 33px 57px;
}

.el-button+.el-button {
  margin-left: 20px;
}

/deep/.transItem .el-form-item__content {
  line-height: 24px !important;
}

.addImgDeviceDialog {
  /deep/.el-dialog {
    height: 85%;
    box-sizing: border-box;

    /deep/.el-dialog__body {
      box-sizing: border-box;
      height: 100%;
    }
  }
}

/*兼容火狐/deep/失效问题*/
.addImgDeviceDialog {
  /deep/.el-dialog {
    height: 85%;
    box-sizing: border-box;

    .el-dialog__body {
      box-sizing: border-box;
      height: 100%;
    }
  }
}

.el-checkbox {
  margin-right: 15px;
}
</style>
<template>
  <el-dialog v-el-drag-dialog :title="dialogTitle" :append-to-body='true' :visible.sync="AddImgDeviceShow"
    :before-close="AddImgDeviceClose" class="addImgDeviceDialog" width="1230px" top="3%" center>
    <div class="clear_fixed" style="height:100%;overflow-y: auto;margin-top: -7px">
      <el-form class="clear_fixed" label-position="right" label-width="100px" :disabled="dialogType === 'view'"
        :model="dialogData" :rules="dialogDataRules" ref="dialogDataForm">
        <div class="clear_fixed fl bbd pb26" style=" width: 1100px;">
          <div class="f18 mb20 clr_333" style="margin-top: 27px">基本信息</div>
          <div class="w100 mt30 clear_fixed">
            <el-form-item label="系统名称：" label-width="98px" class="fl" prop="system_id">
              <el-select :disabled="group !== 'tenancy'" v-model="dialogData.system_id" placeholder="请选择系统名称"
                size="medium" style="width:250px" clearable>
                <el-option v-for="item in systemsLiteList" :key="item.id" :label="item.name" :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="机构名称：" label-width="110px" class="fl" prop="institution_id">
              <el-select :disabled="institutionsLiteList.length === 0" v-model="dialogData.institution_id"
                placeholder="请选择机构名称" size="medium" style="width:250px" clearable>
                <el-option v-for="item in institutionsLiteList" :key="item.id" :label="item.name" :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="前置机：" label-width="110px" class="fl" prop="front_node_key">
              <el-select v-model="dialogData.front_node_key" placeholder="请选择前置机" size="medium" style="width:250px"
                clearable>
                <el-option v-for="item in frontnodesInfo" :key="item.id" :label="item.front_node_name" :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </div>
          <div class="w100 mt10 clear_fixed">
            <el-form-item label="设备名称：" label-width="98px" class="fl" prop="modality_name">
              <el-input size="medium" placeholder="请输入设备名称" style="width:250px;" v-model="dialogData.modality_name"
                clearable>
              </el-input>
            </el-form-item>
            <el-form-item label="设备类型：" label-width="110px" class="fl" prop="modality_type">
              <el-select v-model="dialogData.modality_type" clearable placeholder="请选择设备类型" size="medium"
                style="width:250px">
                <el-option v-for="(item, index) in modalityTypeOptions" :value="item.dic_define_value"
                  :label="item.dic_define_value" :key="index">
                </el-option>
                <el-option value="Viewer" label="Viewer">
                </el-option>
                <el-option value="Other" label="Other">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="设备地址：" label-width="110px" class="fl" prop="modality_host">
              <el-input size="medium" placeholder="请输入设备地址" style="width:250px;" v-model="dialogData.modality_host"
                clearable>
              </el-input>
            </el-form-item>
          </div>
        </div>
        <div class="clear_fixed fl bbd pb15 mt30" style=" width: 1100px;">
          <div class="f18 mb20 clr_333">
            <span class="mr20">设备工作列表服务</span>
            <el-switch v-show="dialogType !== 'view'" v-model="mwl_roleIsSwitch1">
            </el-switch>
          </div>
          <div class="w100 mt10 mb10 clear_fixed">
            <el-form-item label="角色：" prop="mwl_role" class="fl">
              <el-radio-group v-model="dialogData.mwl_role" :disabled="!mwl_roleIsSwitch1" size="medium">
                <el-radio :label="0">SCU</el-radio>
                <el-radio :label="1">SCP</el-radio>
                <el-radio :label="2">SCP&SCU</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="应用标识：" label-width="102px" prop="mwl_aet" class="fl">
              <el-input size="medium" placeholder="请输入应用标识" style="width:250px;" v-model="dialogData.mwl_aet"
                :disabled="!mwl_roleIsSwitch1" clearable>
              </el-input>
            </el-form-item>
            <el-form-item v-if="dialogData.mwl_role === 1 || dialogData.mwl_role === 2" label="端口号：" label-width="110px"
              class="fl" prop="mwl_port	">
              <el-input size="medium" placeholder="请输入端口号" style="width:250px;" v-model="dialogData.mwl_port"
                :disabled="!mwl_roleIsSwitch1" clearable>
              </el-input>
            </el-form-item>
          </div>
          <div class="w100 clear_fixed">

            <el-form-item label="检查机房：" label-width="100px" class="fl" prop="modality_worklist.exam_room_id">
              <el-select :disabled="ObseRoomList.length === 0 || !mwl_roleIsSwitch1" multiple collapse-tags
                :multiple-limit="3" v-model="dialogData.modality_worklist.exam_room_id" placeholder="请选择检查机房"
                size="medium" style="width:250px" clearable>
                <el-option v-for="item in ObseRoomList" :key="item.id" :label="item.room_name" :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>

            <el-form-item label="映射类型：" label-width="110px" class="fl" prop="modality_worklist.mapping_type">
              <el-input size="medium" placeholder="请输入映射类型（RIS类型）" style="width:250px;"
                v-model="dialogData.modality_worklist.mapping_type" :disabled="!mwl_roleIsSwitch1" clearable>
              </el-input>
            </el-form-item>
          </div>
          <div class="w100 mt10 clear_fixed">

            <el-form-item label="返回类型：" label-width="100px" class="fl" prop="modality_worklist.return_type">
              <el-input size="medium" placeholder="请输入返回类型（设备类型）" style="width:250px;"
                v-model="dialogData.modality_worklist.return_type" :disabled="!mwl_roleIsSwitch1" clearable>
              </el-input>
            </el-form-item>
            <el-form-item label="最大返回记录：" label-width="110px" class="fl" prop="modality_worklist.return_number">
              <el-input-number style="width: 100px" size="medium" v-model="dialogData.modality_worklist.return_number"
                controls-position="right" :min="1" :disabled="!mwl_roleIsSwitch1"></el-input-number>
            </el-form-item>
            <el-form-item label="限制预检时间：" label-width="260px" class="fl" prop="modality_worklist.scheduled_date_range">
              <el-input-number style="width: 100px" size="medium"
                v-model="dialogData.modality_worklist.scheduled_date_range" controls-position="right" :min="1"
                :disabled="!mwl_roleIsSwitch1"></el-input-number>
              <span class="ml10">天内</span>
            </el-form-item>
          </div>
          <div class="w100 mt10 clear_fixed">

            <el-form-item label="检查范围：" label-width="100px" class="fl" prop="modality_worklist.business_range_index">
              <el-select v-model="dialogData.modality_worklist.business_range_index" placeholder="请选择检查范围" size="medium"
                :disabled="!mwl_roleIsSwitch1" style="width:250px" clearable>
                <el-option :value="0" label="登记->QA未完成（默认）"></el-option>
                <el-option :value="1" label="仅提供签到后的记录"></el-option>
                <el-option :value="2" label="允许查询已检查的记录"></el-option>
                <el-option :value="3" label="允许查询已报告的记录"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="字符集：" label-width="110px" class="fl" prop="modality_worklist.specific_character_set">
              <el-select v-model="dialogData.modality_worklist.specific_character_set" allow-create filterable
                default-first-option placeholder="请选择字符集" size="medium" :disabled="!mwl_roleIsSwitch1" style="width:250px"
                clearable>
                <el-option value="ISO_IR 100" label="ISO_IR 100"></el-option>
                <el-option value="ISO_IR 87" label="ISO_IR 87"></el-option>
                <el-option value="\ISO 2022 GBK" label="\ISO 2022 GBK"></el-option>
                <el-option value="GB18030" label="GB18030"></el-option>
              </el-select>
            </el-form-item>
          </div>
          <div class="f18 mb20 clr_333 mt20 ml50">
            <span class="mr20">提供检查部位</span>
            <el-switch v-show="dialogType !== 'view'" v-model="dialogData.modality_worklist.is_return_exam_body_part"
              :disabled="!mwl_roleIsSwitch1" :active-value="1" :inactive-value="0">
            </el-switch>
            <div class="clear_fixed mt20">
              <div class="w206 fl">
                <el-form-item label-width="0" class="transItem" prop="modality_worklist.is_by_rp_code">
                  <el-checkbox v-model="dialogData.modality_worklist.is_by_rp_description" :true-label="1"
                    :false-label="0" :disabled="!dialogData.modality_worklist.is_return_exam_body_part" class="mb15">RP
                    Description 传递</el-checkbox>
                  <el-checkbox v-model="dialogData.modality_worklist.is_by_rp_code"
                    :disabled="!dialogData.modality_worklist.is_return_exam_body_part" :true-label="1" :false-label="0">RP
                    Code 传递</el-checkbox>
                </el-form-item>
              </div>
              <div class="w214 fl">
                <el-form-item label-width="0" class="transItem">
                  <el-checkbox v-model="dialogData.modality_worklist.is_by_sps_description"
                    :disabled="!dialogData.modality_worklist.is_return_exam_body_part" :true-label="1" :false-label="0"
                    class="mb15">SPS Description 传递</el-checkbox>
                  <el-checkbox v-model="dialogData.modality_worklist.is_by_sps_code"
                    :disabled="!dialogData.modality_worklist.is_return_exam_body_part" :true-label="1"
                    :false-label="0">SPS Code 传递(标准)</el-checkbox>
                </el-form-item>
              </div>
              <div class="w188 fl">
                <el-form-item label-width="0" prop="modality_worklist.eng_or_chn_body_part">
                  <el-radio-group v-model="dialogData.modality_worklist.eng_or_chn_body_part"
                    :disabled="!dialogData.modality_worklist.is_return_exam_body_part">
                    <el-radio :label="0" class="mt5 mb15">提供英文部位名称</el-radio>
                    <el-radio :label="1" class="mt8 mb2">提供中文部位名称</el-radio>
                  </el-radio-group>
                </el-form-item>
              </div>
              <div class="w188 fl">
                <el-form-item label-width="0" prop="modality_worklist.one_or_multi_body_part">
                  <el-radio-group v-model="dialogData.modality_worklist.one_or_multi_body_part"
                    :disabled="!dialogData.modality_worklist.is_return_exam_body_part">
                    <el-radio :label="0" class="mt5 mb15">支持单个部位</el-radio>
                    <el-radio :label="1" class="mt8 mb2">支持多个部位</el-radio>
                  </el-radio-group>
                </el-form-item>
              </div>
            </div>
          </div>
          <div class="f18 clr_333 ml50">
            <span class="mr20">参数选项</span>
            <div class="mt20">
              <el-form-item label-width="0" class="dib mr15" prop="modality_worklist.is_return_chn_name">
                <el-checkbox v-model="dialogData.modality_worklist.is_return_chn_name" :disabled="!mwl_roleIsSwitch1"
                  :true-label="1" :false-label="0">提供中文姓名</el-checkbox>
                <span>(
                  <el-checkbox v-model="dialogData.modality_worklist.is_return_chn_name_only" :true-label="1"
                    :false-label="0"
                    :disabled="!dialogData.modality_worklist.is_return_chn_name || !mwl_roleIsSwitch1">仅提供中文姓名</el-checkbox>
                  )</span>
              </el-form-item>
              <el-checkbox class="mr15" v-model="dialogData.modality_worklist.is_return_age"
                :disabled="!mwl_roleIsSwitch1" :true-label="1" :false-label="0">提供年龄</el-checkbox>
              <el-checkbox v-model="dialogData.modality_worklist.is_return_height" :disabled="!mwl_roleIsSwitch1"
                :true-label="1" :false-label="0" class="mr0">提供身高</el-checkbox>
              <el-form-item label="单位：" label-width="50px" class="dib" prop="modality_worklist.height_unit">
                <el-select v-model="dialogData.modality_worklist.height_unit" :disabled="!mwl_roleIsSwitch1"
                  placeholder="请选择" size="medium" style="width:100px" clearable>
                  <el-option value="mm" label="毫米"></el-option>
                  <el-option value="cm" label="厘米"></el-option>
                  <el-option value="m" label="米"></el-option>
                </el-select>
              </el-form-item>
              <el-checkbox class="ml15" v-model="dialogData.modality_worklist.is_return_weight"
                :disabled="!mwl_roleIsSwitch1" :true-label="1" :false-label="0">提供体重</el-checkbox>
              <el-checkbox v-model="dialogData.modality_worklist.is_return_birth_date" :disabled="!mwl_roleIsSwitch1"
                :true-label="1" :false-label="0">提供出生日期</el-checkbox>
              <el-checkbox v-model="dialogData.modality_worklist.is_add_hospital_name_chs" :disabled="!mwl_roleIsSwitch1"
                :true-label="1" :false-label="0">附加医院中文名</el-checkbox>
              <el-checkbox v-model="dialogData.modality_worklist.is_switch_patient_id_acc" :disabled="!mwl_roleIsSwitch1"
                :true-label="1" :false-label="0">检查编号与患者编号互置(请重启Worklist服务和Storage服务使其生效)</el-checkbox>
            </div>
          </div>
        </div>
        <div class="clear_fixed fl bbd pb15 mt30" style=" width: 1100px;">
          <div class="f18 mb20 clr_333">
            <span class="mr20">影像存储服务</span>
            <el-switch v-show="dialogType !== 'view'" v-model="store_roleIsSwitch1">
            </el-switch>
          </div>
          <div class="w100 mt10 clear_fixed">
            <el-form-item label="角色：" class="dib" prop="store_role">
              <el-radio-group v-model="dialogData.store_role" :disabled="!store_roleIsSwitch1">
                <el-radio :label="0">SCU</el-radio>
                <el-radio :label="1">SCP</el-radio>
                <el-radio :label="2">SCP&SCU</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="应用标识：" label-width="98px" class="dib" prop="store_aet">
              <el-input size="medium" placeholder="请输入应用标识" style="width:250px;" v-model="dialogData.store_aet"
                :disabled="!store_roleIsSwitch1" clearable>
              </el-input>
            </el-form-item>
            <el-form-item v-if="dialogData.store_role === 1 || dialogData.store_role === 2" label="端口号："
              label-width="117px" class="dib" prop="store_port">
              <el-input size="medium" placeholder="请输入端口号" style="width:250px;" v-model="dialogData.store_port"
                :disabled="!store_roleIsSwitch1" clearable>
              </el-input>
            </el-form-item>
          </div>
          <div class="w100 mt10 clear_fixed">
            <el-form-item label="存储语法：" label-width="100px" class="fl" prop="transfer_syntax">
              <el-select v-model="dialogData.transfer_syntax" clearable placeholder="请选择存储语法" size="medium"
                style="width:250px">
                <el-option :value=-1 label="Default">
                </el-option>
                <el-option :value=21 label="JPEGProcess14SV1">
                </el-option>
              </el-select>
            </el-form-item>
          </div>
          <div class="w100 mt10 clear_fixed ml50">
            <el-checkbox v-model="dialogData.special_match_rule" :disabled="!store_roleIsSwitch1" :true-label="1"
              :false-label="0">当设备作为C-STORE SCU时，检查编号为空或错误，允许服务端采用患者编号+检查类型+检查日期作为检查记录匹配条件（注意：非必须情况下勿选）</el-checkbox>
          </div>
        </div>
        <div class="clear_fixed fl pb15 mt30" style=" width: 1100px;">
          <div class="f18 mb20 clr_333">
            <span class="mr20">查询获取服务</span>
            <el-switch v-show="dialogType !== 'view'" v-model="qr_roleIsSwitch1">
            </el-switch>
          </div>
          <div class="w100 mt10 clear_fixed">
            <el-form-item label="角色：" class="dib" prop="qr_role">
              <el-radio-group v-model="dialogData.qr_role" :disabled="!qr_roleIsSwitch1">
                <el-radio v-model="dialogData.qr_role" :label="0">SCU</el-radio>
                <el-radio v-model="dialogData.qr_role" :label="1">SCP</el-radio>
                <el-radio v-model="dialogData.qr_role" :label="2">SCP&SCU</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="应用标识：" label-width="98px" class="dib" prop="qr_aet">
              <el-input size="medium" placeholder="请输入应用标识" style="width:250px;" v-model="dialogData.qr_aet"
                :disabled="!qr_roleIsSwitch1" clearable>
              </el-input>
            </el-form-item>
            <el-form-item v-if="dialogData.qr_role === 1 || dialogData.qr_role === 2" label="端口号：" label-width="117px"
              class="dib" prop="qr_port">
              <el-input size="medium" placeholder="请输入端口号" style="width:250px;" v-model="dialogData.qr_port"
                :disabled="!qr_roleIsSwitch1" clearable>
              </el-input>
            </el-form-item>
          </div>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer mt20 mb20 fr" style="margin-right: 57px">
        <el-button @click="AddImgDeviceClose" size="medium">关闭</el-button>
        <el-button v-if="dialogType !== 'view'" type="primary" @click="AddImgDeviceSave('dialogDataForm')" size="medium">确
          定</el-button>
      </div>
    </div>
  </el-dialog>
</template>

<script>
import CommonTable from '@/components/common/CommonTable'
import { validURL, validIP, validPort } from '@/utils/validate'
import { mapGetters } from 'vuex'

export default {
  data() {
    let requiredValidator = function (tip) {
      return (rule, value, callback) => {
        if (value === '') {
          callback(new Error(tip))
        } else {
          callback()
        }
      }
    }
    let urlValidator = (rule, value, callback) => {
      if (value !== '') {
        if (validURL(value) || validIP(value)) {
          callback()
        } else {
          callback(new Error('设备地址格式错误'))
        }
      } else {
        callback(new Error('请输入设备地址'))
      }
    }
    let mwlValidator = (tip) => {
      return (rule, value, callback) => {
        if (value === '' && this.mwl_roleIsSwitch1) {
          callback(new Error(tip))
        } else {
          callback()
        }
      }
    }
    let mwlIptNumValidator = (iptName) => {
      return (rule, value, callback) => {
        if (this.mwl_roleIsSwitch1) {
          if (value === undefined) {
            callback(new Error('请输入'))
          } else if (value && !Number.isInteger(value)) {
            this.dialogData.modality_worklist[iptName] = parseInt(value)
          } else {
            callback()
          }
        } else {
          if (value &&!Number.isInteger(value)) {
            
            this.dialogData.modality_worklist[iptName] = parseInt(value)
          } else {
            callback()
          }
        }
      }
    }
    let roleValidator = (roleName) => {
      return (rule, value, callback) => {
        if (this.dialogData[roleName] === '') {
          callback(new Error('请选择角色'))
        } else {
          
          callback()
        }
      }
    }
    let portValidator = (roleName) => {
      return (rule, value, callback) => {
        if (this.dialogData[roleName] === 1 || this.dialogData[roleName] === 2) {
          if (value !== '') {
            if (validPort(value)) {
              callback()
            } else {
              callback(new Error('端口号范围为0-65535'))
            }
          } else {
            callback(new Error('请输入端口号'))
          }
        } else {
          callback()
        }
      }
    }
    let transValidator = (rule, value, callback) => {
      let { is_return_exam_body_part, is_by_rp_description, is_by_rp_code, is_by_sps_description, is_by_sps_code } = this.dialogData.modality_worklist
      if (is_return_exam_body_part === 1 && is_by_rp_description === 0 && is_by_rp_code === 0 && is_by_sps_description === 0 && is_by_sps_code === 0) {
        callback(new Error('请选择传递方式'))
      } else {
        callback()
      }
    }
    let radioValidator = (radioName, tip) => {
      return (rule, value, callback) => {
        if (this.dialogData.modality_worklist.is_return_exam_body_part === 1 && this.dialogData.modality_worklist[radioName] === '') {
          callback(new Error(tip))
        } else {
          callback()
        }
      }
    }
    // let provideValidator = (rule, value, callback) => {
    //   let { is_return_exam_body_part, is_return_chn_name, is_return_age, is_return_height, is_return_weight } = this.dialogData.modality_worklist
    //   if(is_return_exam_body_part === 1 && is_return_chn_name === 0 && is_return_age === 0 && is_return_height === 0 && is_return_weight === 0) {
    //     callback(new Error('请选择提供项'))
    //   }else {
    //     callback()
    //   }
    // }
    let unitValidator = (rule, value, callback) => {
      let { is_return_exam_body_part, is_return_height, height_unit } = this.dialogData.modality_worklist
      if (is_return_exam_body_part === 1 && is_return_height === 1 && height_unit === '') {
        callback(new Error('请选择单位'))
      } else {
        callback()
      }
    }
    let storeValidator = (tip) => {
      return (rule, value, callback) => {
        if (value === '' && this.store_roleIsSwitch1) {
          callback(new Error(tip))
        } else {
          callback()
        }
      }
    }
    let qrValidator = (tip) => {
      return (rule, value, callback) => {
        if (value === '' && this.qr_roleIsSwitch1) {
          callback(new Error(tip))
        } else {
          callback()
        }
      }
    }
    return {
      dialogTitle: '',
      dialogData: {
        id: 0,
        system_id: '',
        system_name: '',
        institution_id: '',
        institution_name: '',
        front_node_key: '',
        modality_name: '',
        modality_type: '',
        modality_host: '',
        store_role: '',
        transfer_syntax: -1,
        special_match_rule: 0,
        store_aet: '',
        store_port: '',
        qr_role: '',
        qr_aet: '',
        qr_port: '',
        mwl_role: '',
        mwl_aet: '',
        mwl_port: '',
        modality_worklist: {
          exam_room_id: [],
          scheduled_date_range: 1,
          mapping_type: '',
          return_type: '',
          return_number: 50,
          business_range_index: 0,
          is_return_chn_name: 0,
          is_return_chn_name_only: 0,
          is_return_age: 0,
          is_return_height: 0,
          height_value_type: '',
          height_unit: '',
          is_return_weight: 0,
          weight_value_type: '',
          is_return_exam_body_part: 1,
          is_by_rp_description: 0,
          is_by_rp_code: 0,
          is_by_sps_description: 0,
          is_by_sps_code: 0,
          eng_or_chn_body_part: '',
          one_or_multi_body_part: '',
          specific_character_set: 'ISO_IR 100',
          is_add_hospital_name_chs: 0,
          is_switch_patient_id_acc: 0,
          is_return_birth_date: 0
        },
      },
      dialogDataRules: {
        system_id: [{
          trigger: 'blur',
          validator: requiredValidator('请选择系统名称')
        }],
        institution_id: [{
          trigger: 'blur',
          validator: requiredValidator('请选择机构名称')
        }],
        modality_name: [{
          trigger: 'blur',
          validator: requiredValidator('请输入设备名称')
        }],
        // modality_type: [{
        //   trigger: 'blur',
        //   validator: requiredValidator('请选择设备类型')
        // }],
        modality_host: [{
          trigger: 'blur',
          validator: urlValidator
        }],
        mwl_role: [{
          trigger: 'blur',
          validator: roleValidator('mwl_role')
        }],
        mwl_aet: [{
          trigger: 'blur',
          validator: mwlValidator('请输入应用标识')
        }],
        mwl_port: [{
          trigger: 'blur',
          validator: portValidator('mwl_role')
        }],
        'modality_worklist.business_range_index': [{
          trigger: 'blur',
          validator: mwlValidator('请选择检查范围')
        }],
        'modality_worklist.specific_character_set': [{
          trigger: 'blur',
          validator: mwlValidator('请选择字符集')
        }],
        'modality_worklist.return_number': [{
          trigger: 'blur',
          validator: mwlIptNumValidator('return_number')
        }],
        'modality_worklist.scheduled_date_range': [{
          trigger: 'blur',
          validator: mwlIptNumValidator('scheduled_date_range')
        }],
        'modality_worklist.is_by_rp_code': [{
          trigger: 'blur',
          validator: transValidator
        }],
        'modality_worklist.eng_or_chn_body_part': [{
          trigger: 'blur',
          validator: radioValidator('eng_or_chn_body_part', '请选择部位名称')
        }],
        'modality_worklist.one_or_multi_body_part': [{
          trigger: 'blur',
          validator: radioValidator('one_or_multi_body_part', '请选择支持部位')
        }],
        // 'modality_worklist.is_return_chn_name': [{
        //   trigger: 'blur',
        //   validator: provideValidator
        // }],
        'modality_worklist.height_unit': [{
          trigger: 'blur',
          validator: unitValidator
        }],
        store_role: [{
          trigger: 'blur',
          validator: roleValidator('store_role')
        }],
        store_aet: [{
          trigger: 'blur',
          validator: storeValidator('请输入应用标识')
        }],
        store_port: [{
          trigger: 'blur',
          validator: portValidator('store_port')
        }],
        qr_role: [{
          trigger: 'blur',
          validator: roleValidator('qr_role')
        }],
        qr_aet: [{
          trigger: 'blur',
          validator: qrValidator('请输入应用标识')
        }],
        qr_port: [{
          trigger: 'blur',
          validator: portValidator('qr_role')
        }]
      },
      mwl_roleIsSwitch: true,
      store_roleIsSwitch: true,
      qr_roleIsSwitch: true,
      modalityTypeOptions: [], // 设备类型,
      storageGrammars: ["Default", "JPEGProcess14SV1"],
      institutionsLiteList: [], // 机构名称
      ObseRoomList: [], // 检查机房
      isInstitutionsClear: 1, // 打开dialog后第一次改变系统名称,不清空机构名称的值,后面每次都清空,dialogType为add时,从第一次开始就清空机构名称的值
      productCode: ''
    }
  },
  props: ['AddImgDeviceShow', 'rowId', 'dialogType', 'frontnodesInfo', 'systemsLiteList'],
  computed: {
    ...mapGetters(['group', 'systemid']),
    mwl_roleIsSwitch1: {
      get() {
        return this.mwl_roleIsSwitch
      },
      set(val) {
        this.mwl_roleIsSwitch = val
        this.dialogData.mwl_role = val ? '' : -1
        this.dialogData.modality_worklist.is_return_exam_body_part = val ? 1 : 0;
      }
    },
    store_roleIsSwitch1: {
      get() {
        return this.store_roleIsSwitch
      },
      set(val) {
        this.store_roleIsSwitch = val
        this.dialogData.store_role = val ? '' : -1
      }
    },
    qr_roleIsSwitch1: {
      get() {
        return this.qr_roleIsSwitch
      },
      set(val) {
        this.qr_roleIsSwitch = val
        this.dialogData.qr_role = val ? '' : -1
      }
    }
  },
  watch: {
    'dialogData.mwl_role': {
      handler(newVal) {
        if (newVal === -1 || newVal == null) {
          this.mwl_roleIsSwitch = false
        } else {
          this.mwl_roleIsSwitch = true
        }
      }
    },
    'dialogData.store_role': {
      handler(newVal) {
        if (newVal === -1 || newVal == null) {
          this.store_roleIsSwitch = false
        } else {
          this.store_roleIsSwitch = true
        }
      }
    },
    'dialogData.qr_role': {
      handler(newVal) {
        console.log('数据不对哦',newVal);
      
        if (newVal === -1 || newVal == null) {
          this.qr_roleIsSwitch = false
        } else {
          this.qr_roleIsSwitch = true
        }
      }
    },
    'dialogData.modality_worklist.is_return_chn_name': {
      handler(newVal) {
        if (newVal === 0) {
          this.dialogData.modality_worklist.is_return_chn_name_only = 0
        }
      }
    },
    dialogType(newVal) { // 修改弹窗标题
      this.dialogTitle = newVal === 'add' ? '新增影像设备' : newVal === 'view' ? '查看' : newVal === 'modify' ? '修改' : ''
    },
    AddImgDeviceShow(newVal) {
      this.$nextTick(() => {
        if (newVal) {
          // // 这里要改成 this.group
          if (this.group === 'dept') { // 科室角色
            this.$nextTick(() => {
              this.dialogData.system_id = this.systemid
            })
          }
          this.$refs['dialogDataForm'].resetFields();
          this.dialogData = this.$options.data().dialogData
          if (this.dialogType !== 'add') {
            this.getImgDevice(this.rowId)
          }
        } else {
          this.isInstitutionsClear = 1
        }
      })
    },
    'dialogData.system_id': {
      handler: function (newVal) {
        console.log(newVal)
        console.log(this.dialogData.institution_id)
        console.log(this.isInstitutionsClear)
        if (newVal === '') {
          this.dialogData.system_name = ''
          this.modalityTypeOptions = []
        } else {
          this.systemsLiteList.forEach((ele) => {
            if (ele.id === newVal) {
              this.dialogData.system_name = ele.name
            }
          })
          if (this.dialogType === 'add') {
            this.dialogData.institution_id = ''
            this.ObseRoomList = []
            this.dialogData.modality_worklist.exam_room_id = []
          }
          if (this.dialogType === 'modify' && this.isInstitutionsClear === 2) {
            this.dialogData.institution_id = ''
            this.ObseRoomList = []
            this.dialogData.modality_worklist.exam_room_id = []
          }
          this.getInstitutionsLiteList(newVal) // 获取机构名称
          this.getSystemDetail(newVal)
        }
      },
      immediate: true
    },
    'dialogData.institution_id': {
      handler: function (newVal) {
        if (newVal === '') {
          this.dialogData.institution_name = ''
        } else {
          this.institutionsLiteList.forEach((ele) => {
            if (ele.id === newVal) {
              this.dialogData.institution_name = ele.name
            }
          })
          if (this.dialogType === 'add') {
            this.dialogData.modality_worklist.exam_room_id = []
          }
          if (this.dialogType === 'modify' && this.isInstitutionsClear === 2) {
            this.dialogData.modality_worklist.exam_room_id = []
          }
          this.getObseRoom(newVal, this.dialogData.system_id)
        }
      }
    }
  },
  mounted(){
    console.log('没有数据哦?',this.dialogData);
  },
  methods: {
    AddImgDeviceClose() {
      this.$emit('AddImgDeviceClose', '')
    },
    AddImgDeviceSave(formName) {
      console.log('确定按钮点击了吗？',formName,this.$refs[formName]);
      console.log('为什么没有报错信息哦?',this.$refs[formName].validate());

      this.$refs[formName].validate((valid) => {
        
        console.log('验证失败吗？',valid);
        if (valid) {
          // this.dialogData.front_node_key = this.dialogData.front_node_key === '' ? '-1' : this.dialogData.front_node_key
          // this.dialogData.modality_worklist.exam_room_id = this.dialogData.modality_worklist.exam_room_id === '' ? '-1' : this.dialogData.modality_worklist.exam_room_id
          const submitData = {
            ...this.dialogData,
          }
          if (this.dialogType === 'add') {
            this.addImgDevice(submitData)
          } else if (this.dialogType === 'modify') {
            this.modifyImgDevice(submitData)
          }
        } else {
          return false
        }
      })
      console.log('这个方法没有执行哦');
    },
    async addImgDevice(submitData) {
      const res = await this.$pacsApi.pacsApi.addImgDevice(submitData)
      const { code, msg } = res
      if (code === 0) {
        this.$message({
          type: 'success',
          message: '新增影像设备成功！'
        })
        this.AddImgDeviceClose()
        this.$emit('refreshTable')
      } else {
        this.$message.error(msg)
      }
    },
    async modifyImgDevice(submitData) {
      const res = await this.$pacsApi.pacsApi.modifyImgDevice(submitData)
      const { code, msg } = res
      if (code === 0) {
        this.$message({
          type: 'success',
          message: '修改影像设备成功！'
        })
        this.AddImgDeviceClose()
        this.$emit('refreshTable')
      } else {
        this.$message.error(msg)
      }
    },
    async getImgDevice(id) {
      const res = await this.$pacsApi.pacsApi.getImgDevice(id)
      const { code, data, msg } = res
      if (code === 0) {
        if (!data.modality_worklist) {
          data.modality_worklist = {}
        }
        this.dialogData = Object.assign(this.dialogData, data)
        this.$nextTick(() => {
          this.isInstitutionsClear = 2
        })
        // this.dialogData.front_node_key = data.front_node_key === '-1' ? '' : data.front_node_key
        // this.dialogData.modality_worklist.exam_room_id = data.modality_worklist.exam_room_id === '-1' ? '' : data.modality_worklist.exam_room_id
      } else {
        this.$message.error(msg)
      }
    },
    async getInstitutionsLiteList(val) {
      if (val) {
        let res = await this.$pacsApi.pacsApi.getInstitutionsLiteList({ system_id: val })
        let { code, data } = res
        if (code === 0) {
          this.institutionsLiteList = data
        }
      }
    },
    async getObseRoom(val, system_id) {
      if (val) {
        let res = await this.$pacsApi.pacsApi.getObseRoom({ roomState: 10, organizationId: val, SystemId: system_id })
        let { code, data } = res
        if (code === 0) {
          this.ObseRoomList = data
        }
      }
    },
    // 获取系统详情
    async getSystemDetail(systemid) {
      let res = await this.$pacsApi.pacsApi.getSystemDetail({ id: systemid })
      let { code, data } = res
      if (code === 0) {
        this.productCode = data.product_code
        // 请求设备类型
        this.getDicDefine(this.productCode)
        //请求存储语法
        this.getStorageGrammars(this.productCode)
      }
    },
    // 获取设备类型
    async getDicDefine(productName) {
      let res = await this.$pacsApi.pacsApi.getDicDefine({ dicTypeCode: 'ServiceSectId', DicDefineAttribute: productName, SystemId: this.dialogData.system_id })
      let { code, data } = res
      if (code === 0) {
        this.modalityTypeOptions = data
      }
    },
    //获取存储语法
    async getStorageGrammars(productName) {
      // let res = await this.$pacsApi.pacsApi.getStorageGrammars({ dicTypeCode: 'ServiceSectId', DicDefineAttribute: productName, SystemId: this.dialogData.system_id  })
      // let { code, data } = res
      // if(code === 0) {
      //   this.storageGrammars = data
      // }
    },
  },
  components: {
    CommonTable
  }
}
</script>
